<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人</title>
    {% load static %}
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
            line-height: 1.6;
            display: flex;
            flex-direction: row;
            min-height: 100vh;
        }

        header {
            background: #35424a;
            color: #ffffff;
            text-align: center;
            padding: 20px 0;
            width: 100%;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1000;
        }

        footer {
            background: #35424a;
            color: #ffffff;
            text-align: center;
            padding: 20px 0;
            margin-top: auto;
            width: 100%;
            position: fixed;
            bottom: 0;
            left: 0;
        }

        .container {
            display: flex;
            width: 100%;
            margin-top: 100px;
            margin-bottom: 80px;
        }

        .user-info {
            padding: 40px 20px;
            background-color: #ffffff;
            margin-top: 50px;
            border-radius: 8px;
            max-width: 250px;
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
        }

        .article-list {
            flex: 1;
            padding: 20px;
            background-color: #ffffff;
            margin-top: 50px;
            margin-left: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
        }

        .article-item {
            border-bottom: 1px solid #e0e0e0;
            padding: 10px 0;
        }

        .article-item:last-child {
            border-bottom: none;
        }

        .profile-img {
            text-align: center;
            margin-bottom: 20px;
        }

        .profile-img img {
            border-radius: 50%;
            width: 100px;
            height: 100px;
            border: 2px solid #35424a;
        }

        .info {
            text-align: left;
        }

        .info p {
            margin: 10px 0;
            font-size: 16px;
        }

        .info strong {
            color: #35424a;
        }

        .button {
            background-color: #35424a; /* 按钮背景颜色 */
            color: #ffffff; /* 文本颜色设为白色 */
            border: none; /* 无边框 */
            padding: 10px; /* 内边距 */
            border-radius: 5px; /* 圆角 */
            cursor: pointer; /* 鼠标指针为手型 */
            margin-top: 10px; /* 上边距 */
            text-decoration: none; /* 去掉下划线 */
        }

        .button:hover {
            background-color: #455a64; /* 悬停时按钮背景颜色 */
        }

        .button a {
            color: #ffffff; /* 确保链接文本颜色为白色 */
            text-decoration: none; /* 去掉下划线 */
        }

        .login-prompt {
            text-align: center;
            margin: 20px;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>
<header>
    <h1>欢迎来到我的博客</h1>
</header>

<div class="container">
    {% if user_info %}
    <div class="user-info">
        <div class="profile-img">
            {% if user_info.head_img %}
                <img src="{{ user_info.head_img.url }}" alt="{{ user_info.user.username }}的头像">
            {% else %}
                <img src="../static/img/default_avatar.jpg" alt="默认头像">
            {% endif %}
        </div>
        <div class="info">
            <p><strong>用户名:</strong> {{ user_info.user.username }}</p>
            <p><strong>年龄:</strong> {{ user_info.age }}</p>
            <p><strong>手机号:</strong> {{ user_info.phone }}</p>
            <p><strong>个人简介:</strong> {{ user_info.desc }}</p>
        </div>

        <!-- 添加修改资料和发布文章的按钮 -->
        <div class="action-buttons" style="text-align: center; margin-top: 20px;">
            <button class="button"><a href="{% url 'change_message' %}">修改资料</a></button>
            <button class="button"><a href="{% url 'submit_essay' %}">发布文章</a></button>
        </div>
    </div>

    <div class="article-list">
        <h2>我的文章</h2>
        {% for article in user_articles %}
            <div class="article-item">
                <h3>{{ article.title }}</h3>
                <p>类型：{{ article.classifier }} | 标签: {% for tag in article.tag.all %}{{ tag.name }}{% if not forloop.last %}, {% endif %}{% endfor %} | {{ article.create_time }}</p>
                <p>{{ article.excerpt }}</p>
                <button class="button"><a href="{% url 'detail' article.id %}">浏览</a></button>
                <button class="button"><a href="{% url 'edit_essay' article.id %}">修改</a></button>
                <form method="POST" action="{% url 'delete_essay' article.id %}" style="display:inline;" onsubmit="return confirmDelete()">
                    {% csrf_token %}
                    <button type="submit" class="button">删除</button>
                </form>
            </div>
        {% empty %}
            <p>还没有发布任何文章。</p>
        {% endfor %}
        <div style="text-align: center; margin-top: 20px;">
            <button class="button"><a href="/article">返回首页</a></button>
        </div>
    </div>
    {% else %}
        <div class="login-prompt">
            <h2>请登录以查看个人信息</h2>
            <p>如果您还没有账户，请<a href="{% url 'register' %}">注册</a></p>
            <p>或者<a href="{% url 'login' %}">登录</a></p>
        </div>
    {% endif %}
</div>

<footer>
    <p>&copy; 2024 我的博客. 保留所有权利.</p>
</footer>
<script>
    function confirmDelete() {
        if (confirm("确认删除此文章？")) {
            alert("删除成功！")
            return true;
        } else {
            return false;
        }
    }
</script>
</body>
</html>
